<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>

</head>


<body>
  <div>
    <form action="http://localhost:3000" method="post">
      <div>
        <label for="">name</label><input type="text" name='_name' value="yeke">
      </div>
      <div>
        <label for="">age</label><input type="text" name="_age" value="20">
      </div>
      <div>
        <input type="submit" value="提交">
      </div>
    </form>
    <div id="getData">22</div>
    <input id="btn" type="button" value="获取数据">
  </div>
</body>
<script type="text/javascript">
  document.getElementById('btn').addEventListener('click', function () {
    console.log('hah');
    getData()
  })

  function getData() {
    console.log('点击了按钮');
    var xhr = new XMLHttpRequest()
    xhr.open('GET', 'http://localhost:3000/', true)
    xhr.onreadystatechange = function () {
      if (xhr.readyState == 4) {
        if (xhr.status == 200) {
          document.getElementById('getData').innerText = xhr.responseText
        }
      }
    }
    xhr.send(null)
  }
</script>

</html>